<?php

namespace app\admin\controller;

use app\admin\service\ConfigService;
use app\common\service\UploadService;
use think\facade\Request;

/**
 * 权限管理
 * Class Rbac
 * @package app\admin\controller
 */
class Upload extends CommonController
{
    // 系统上传配置
    public function config()
    {
        if ($this->isAjax())
        {
            $request = $this->request;
            $formData = $request['form'];
            ConfigService::setConf('sys_upload', 'admin', $formData);
            return $this->success();
        }

        $config = ConfigService::getConf('sys_upload', 'admin');
        $type = ConfigService::getUploadType();

        return view('upload/config', ['data' => $config, 'type' => $type]);
    }

    /**
     * @desc上传相册图片
     * @return \think\response\Json
     */
    public function uploadalbum()
    {
        $request = $this->request;
        $gid = $request['gid'] ?? 0;
        $aid = $this->admin_id;

        // 接受前台传来的file文件
        $file = Request::file('file');
        $data = UploadService::uploadAlbum($file, $gid, $aid);
        return $this->success($data);
    }
}
